package com.astrofizzbizz.stoneedgegui.app;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.InputStream;
import java.util.Date;
import java.util.Random;

import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTabbedPane;
import javax.swing.KeyStroke;
import javax.swing.MenuElement;
import javax.swing.UIManager;
import javax.swing.filechooser.FileNameExtensionFilter;

import com.astrofizzbizz.stoneedgegui.monitor.TelescopeMonitorPanel;
import com.astrofizzbizz.stoneedgegui.simbad.SimbadPanel;
import com.astrofizzbizz.stoneedgegui.utilities.StoneEdgeIIIException;
import com.astrofizzbizz.stoneedgegui.utilities.StoneEdgeIIITunnel;
import com.astrofizzbizz.stoneedgegui.utilities.TelescopeInfo;
import com.astrofizzbizz.stoneedgegui.utilities.TreffersLock;



public class StoneEdgeIIIGui  extends JFrame
{

	private static final long serialVersionUID = 1068728660964862179L;
	protected String version = "v2.0";
	protected String versionDate = "Jan. 6, 2013";
	private String userKey;

	private StoneEdgeIIITunnel stoneEdgeIIITunnel = null;
	private TelescopeInfo telescopeInfo;
	private StatusPanel statusBar = new StatusPanel(4, "Observatory Status");
	private JTabbedPane mainPane;
	private JMenuBar mainMenuBar;
	private JPanel introPanel = null;
	private TelescopeMonitorPanel telescopeMonitorPanel = null;
	private JFrame domeCameraFrame = null;
	private String introPanelTabTitle = "Intro";
	private String domeCameraTabTitle = "Dome Monitor";
	private String astroCatologTabTitle = "Catalog";
	private String targetTabTitle = "Target";
	private JPopupMenu domeCameraPopOutMenu;
	private int domeSleepTimerSeconds = 30;
	private int domeTrackingIntervalHeartBeatCount = 10;
	private int statusTableLength;
	private String astroCatalogXmlFileName = null;
	private String defaultAstroCatalogXmlFileName = "com/astrofizzbizz/stoneedgegui/files/defaultCatalog.xml";
	private String lastDirectoryPath = null;
	private AstroCatalog astroCatalog = null;
	private TargetingPanel targetingPanel = null;
	private ClassLoader loader = null;
	private ImageIcon logoIcon;
	private Date updateDate = new Date();
	private SimbadPanel simbadPanel;
	private String simbadTabTitle = "SIMBAD";

	public StoneEdgeIIIGui(int domeSleepTimerSeconds, int domeTrackingIntervalHeartBeatCount, int statusTableLength, String jFrameTitle) throws StoneEdgeIIIException
	{
		super(jFrameTitle);
		loader = Thread.currentThread().getContextClassLoader();
		logoIcon = new ImageIcon(loader.getResource("com/astrofizzbizz/stoneedgegui/files/StoneEdgeTelescopeLogo.jpg"));
		this.domeSleepTimerSeconds = domeSleepTimerSeconds;
        this.domeTrackingIntervalHeartBeatCount = domeTrackingIntervalHeartBeatCount;
        this.statusTableLength = statusTableLength;
        try 
        {
            UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName());
//            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {}
        
        mainMenuBar = makeMenu();
        setJMenuBar(mainMenuBar);
        
        findMenu(mainMenuBar, "Lock").setEnabled(false);
        findMenuItem(findMenu(mainMenuBar, "Connection"), "Disconnect").setEnabled(false);
        findMenuItem(findMenu(mainMenuBar, "File"), "Open Catalog").setEnabled(false);
        findMenuItem(findMenu(mainMenuBar, "File"), "Reload Default Catalog").setEnabled(false);
        
        setupMainPanel();
        getContentPane().setLayout(new BorderLayout(5,5));
		getContentPane().add(mainPane, BorderLayout.CENTER);
		getContentPane().add(statusBar.getScrollPane(), java.awt.BorderLayout.SOUTH);  
		statusBar.setText("Welcome");
		pack();
		setVisible(true);
		statusBar.getScrollPane().setMinimumSize(statusBar.getScrollPane().getSize());
		statusBar.getScrollPane().setPreferredSize(statusBar.getScrollPane().getSize());

        setIconImage(logoIcon.getImage());
        
        userKey = "A" + new Integer(new Random().nextInt(9999999)).toString() + "Z";
        statusBar.setText("User Key = " + userKey);
 
        addWindowListener(new java.awt.event.WindowAdapter() 
        {
            public void windowClosing(WindowEvent winEvt) 
            {
            	quitProgram();            
            }
        });
	}
	private void setupIntroPanel()
	{
		introPanel = new JPanel();
		introPanel.setLayout(new GridLayout(2,2));
		introPanel.add(new JLabel(new ImageIcon(loader.getResource("com/astrofizzbizz/stoneedgegui/files/M27Small.jpg"))));
		introPanel.add(new JLabel(new ImageIcon(loader.getResource("com/astrofizzbizz/stoneedgegui/files/BackEndSmall.jpg"))));
		introPanel.add(new JLabel(new ImageIcon(loader.getResource("com/astrofizzbizz/stoneedgegui/files/FrontEndSmall.jpg"))));
		introPanel.add(new JLabel(new ImageIcon(loader.getResource("com/astrofizzbizz/stoneedgegui/files/SonomaBrush.jpg"))));
	}
	private void setupMainPanel()
	{
		mainPane= new JTabbedPane();
		

		setupIntroPanel();
		telescopeMonitorPanel = null;
		mainPane.addTab(introPanelTabTitle, introPanel);
		mainPane.addMouseListener(new MyMouseListeners());
		domeCameraPopOutMenu = domeCameraPopOutMenu();
		
	}
	private class MyMouseListeners implements MouseListener
	{

		@Override
		public void mouseClicked(MouseEvent arg0) {
			if (arg0.getButton() == 3)
			{
				int itab = mainPane.getUI().tabForCoordinate(mainPane, arg0.getX(), arg0.getY());
				if ((itab == mainPane.indexOfTab(domeCameraTabTitle)) && (itab >= 0) )
				{
					domeCameraPopOutMenu.show(arg0.getComponent(), arg0.getX(), arg0.getY());
				}
			}
		}
		@Override
		public void mouseEntered(MouseEvent arg0) {}
		@Override
		public void mouseExited(MouseEvent arg0) {}
		@Override
		public void mousePressed(MouseEvent arg0) {}
		@Override
		public void mouseReleased(MouseEvent arg0) {}
	}
	private class MenuBarActionListeners implements ActionListener
	{
		StoneEdgeIIIGui stoneEdgeIIIGui;
		String actionString = "";
		MenuBarActionListeners(String actionString, StoneEdgeIIIGui stoneEdgeIIIGui)
		{
			this.actionString = actionString;
			this.stoneEdgeIIIGui = stoneEdgeIIIGui;
		}
		@Override
		public void actionPerformed(ActionEvent arg0) 
		{
			if (actionString.equals("Connection.Connect"))
			{
				connectToStoneEdgeTunnel();
			}
			if (actionString.equals("Connection.Disconnect"))
			{
				disconnectStoneEdgeTunnel();
			}
			if (actionString.equals("domeCameraPopOutMenu.popout"))
			{
				popOutDomeCamera();
			}
			if (actionString.equals("Help.Help"))
			{
			}
			if (actionString.equals("Help.About"))
			{
				messageDialog("StoneEdge III " + version + "\n" + "Last Updated " + versionDate);
			}
			if (actionString.equals("Help.Contact"))
			{
				String message = "Stone Edge Obervatory Coordinator:";
				message = message + "\n          Vivian Hoette of Yerkes Observatory";
				message = message + "\n          email: vhoette@yerkes.uchicago.edu";
				message = message + "\n          phone: 262-215-1599";
				message = message + "\n Program written by:";
				message = message + "\n          Dave McGinnis";
				message = message + "\n          email: dmcginnis427@gmail.com";
				message = message + "\n          phone: 630-457-4205";
				messageDialog(message);
			}
			if (actionString.equals("File.Exit"))
				quitProgram();
			if (actionString.equals("File.Open Catalog"))
			{
				changeCatalog();
			}
			if (actionString.equals("File.Reload Default Catalog"))
			{
				reloadDefaultCatalog();
			}
			if (actionString.equals("Lock.Change Lock"))
			{
				try {new TelescopeLockDialog(stoneEdgeIIIGui);} catch (StoneEdgeIIIException e) {;}
			}
		}
		
	}
	private JPopupMenu  domeCameraPopOutMenu()
	{
		JPopupMenu Pmenu = new JPopupMenu();
		JMenuItem menuItem = new JMenuItem("Pop Out");
		menuItem.addActionListener(new MenuBarActionListeners("domeCameraPopOutMenu.popout",  this));
		Pmenu.add(menuItem);
		return Pmenu;
	}
	private  JMenuBar makeMenu()
	{
		JMenuBar menuBar = new JMenuBar();
		String menuText[] = {"File","Connection","Lock", "Help"};
        String itemText[][] =
        {
    		{"Open Catalog", "Reload Default Catalog","Exit"},
    		{"Connect", "Disconnect"},
    		{"Change Lock"},
    		{"Help", "About", "Contact"}
    	};

        for (int i = 0; i < menuText.length; i++)
        {
            JMenu menu = new JMenu(menuText[i]);
            menuBar.add (menu);
            
            for (int j = 0; j < itemText[i].length; j++)
            {
                JMenuItem item = new JMenuItem(itemText[i][j]);
                menu.add (item);
                item.addActionListener(new MenuBarActionListeners(menuText[i] + "." +itemText[i][j], this));
        		if (itemText[i][j].equals("Exit"))
        		{
        			item.setAccelerator(KeyStroke.getKeyStroke(
        			        KeyEvent.VK_Q, ActionEvent.CTRL_MASK));

        		}
         		if (itemText[i][j].equals("Help"))
        		{
        			item.setAccelerator(KeyStroke.getKeyStroke(
        			        KeyEvent.VK_H, ActionEvent.CTRL_MASK));

        		}
        		if (itemText[i][j].equals("About"))
        		{
        			item.setAccelerator(KeyStroke.getKeyStroke(
        			        KeyEvent.VK_A, ActionEvent.CTRL_MASK));

        		}
            }
        }
        
        return menuBar;
    }
	JMenu findMenu(JMenuBar menuBar, String menuName)
	{
        MenuElement[] menus =  menuBar.getSubElements();
        for (int ii = 0; ii < menus.length; ++ii)
        {
        	JMenu menu = (JMenu) menus[ii].getComponent();
        	if (menu.getText().equals(menuName)) return menu;
        }
        return null;
	}
	JMenuItem findMenuItem(JMenu menu, String menuItemName)
	{
        if (menu.getItemCount() > 0)
        {
	        for (int ii = 0; ii < menu.getItemCount(); ++ii)
	        {
	        	JMenuItem menuItem = menu.getItem(ii);
	        	if (menuItem.getText().equals(menuItemName)) return menuItem;
	        }
        }
        return null;
	}
	protected void messageDialog(String string)
	{
		JOptionPane.showMessageDialog(this, string);
	}
	protected int optionDialog(String title, String text, String option1, String option2, int defaultOption)
	{
		if (defaultOption < 1) defaultOption = 1;
		if (defaultOption > 2) defaultOption = 2;
		Object[] options = {option1, option2};
		int n = JOptionPane.showOptionDialog(this,
				text,
				title,
				JOptionPane.YES_NO_CANCEL_OPTION,
				JOptionPane.QUESTION_MESSAGE,
				null,
				options,
				options[defaultOption - 1]);
		n= n+ 1;
		return n;
	}
	protected void quitProgram()
	{
    	if (stoneEdgeIIITunnel != null)
    	{
    		try 
    		{
    			statusBar.setText("Checking lock.");
    			TreffersLock treffersLock = new TreffersLock(stoneEdgeIIITunnel);
        		if (getUserKey().equals(telescopeMonitorPanel.getDomeMonitorPanel().getDomeMonitor().getTreffersLock().getSessionID()))
        		{
        			if (!telescopeMonitorPanel.getDomeMonitorPanel().getDomeMonitor().isSlitClosed())
        			{
        				int ichoice = optionDialog("Dome Open", "Dome is still Open!", "Close Dome","Leave Open", 1);
        				if (ichoice == 1)
        				{
         					WaitFrame waitFrame = new WaitFrame("Wait", "Closing dome first! Please Wait", this);
	        				telescopeMonitorPanel.getDomeMonitorPanel().getDomeMonitor().setKeepTrackingOn(false);
	        				String openCommand = "closedown user=remote";
	        				String[] response = null;
	        				response = stoneEdgeIIITunnel.executeCommand(openCommand, 1024);
	        				statusBar.setText(response[0]);
	        				waitFrame.dispose();
	        				messageDialog("Dome Closed");
        				}
        			}
    				statusBar.setText("Clearing lock.");
        			treffersLock.clearLock();
        		}
        		else
        		{
        			if (!telescopeMonitorPanel.getDomeMonitorPanel().getDomeMonitor().isSlitClosed())
        			{
        				messageDialog("The Dome is Open");
        			}
        		}
    		} catch (StoneEdgeIIIException e) {
    			e.printStackTrace();
    		}
    		WaitFrame waitFrame = new WaitFrame("Wait", "Cleaning up dome camera panel. Please Wait", this);
			statusBar.setText("Cleaning up dome camera panel.");
			telescopeMonitorPanel.getDomeMonitorPanel().cleanup();
			statusBar.setText("Disconnecting tunnel.");
    		stoneEdgeIIITunnel.disconnect();
    		try {Thread.sleep(1000);} catch (InterruptedException e) {;}
    		waitFrame.dispose();
    	}
        System.exit(0); 
	}
	private void connectToStoneEdgeTunnel()
	{
		if (stoneEdgeIIITunnel != null)
		{
			JOptionPane.showMessageDialog(this,
				    "Tunnel connected to observatory",
				    "Information",
				    JOptionPane.INFORMATION_MESSAGE);	
			return;
		}
		File privateKey = null;
		try {privateKey = StoneEdgeIIITunnel.privateKey();} 
		catch (StoneEdgeIIIException e1) {e1.messageDialog(this); return;}
		if (privateKey != null)
		{
			WaitFrame waitFrame = new WaitFrame("Wait", "Please wait. Connecting to Tunnel", this);

			try {
				stoneEdgeIIITunnel = new StoneEdgeIIITunnel(privateKey);
				
		        findMenu(mainMenuBar, "Lock").setEnabled(true);
		        findMenuItem(findMenu(mainMenuBar, "Connection"), "Disconnect").setEnabled(true);
		        findMenuItem(findMenu(mainMenuBar, "Connection"), "Connect").setEnabled(false);
		        findMenuItem(findMenu(mainMenuBar, "File"), "Open Catalog").setEnabled(true);
		        
		        telescopeMonitorPanel = new TelescopeMonitorPanel(this);
				mainPane.addTab(domeCameraTabTitle, telescopeMonitorPanel);
				telescopeMonitorPanel.getDomeMonitorPanel().setSize();
		        pack();
				mainPane.setSelectedIndex(mainPane.indexOfTab(domeCameraTabTitle));
				
				targetingPanel = new TargetingPanel(this);
				mainPane.addTab(targetTabTitle, targetingPanel);
				
				simbadPanel = new SimbadPanel(this);
				mainPane.addTab(simbadTabTitle, simbadPanel);
			} 
			catch (StoneEdgeIIIException e) 
			{
				waitFrame.dispose();
				stoneEdgeIIITunnel = null;
				String errorMessage = "Could not connect tunnel to observatory\n" + e.getMessage();
				JOptionPane.showMessageDialog(this,
						errorMessage,
					    "Information",
					    JOptionPane.INFORMATION_MESSAGE);	
				return;
			}
			try 
			{
				if (astroCatalogXmlFileName == null) 
				{
			        InputStream inputStream = loader.getResourceAsStream(defaultAstroCatalogXmlFileName);
					astroCatalog = new AstroCatalog(inputStream, this);
				}
				else
				{
					astroCatalog = new AstroCatalog(astroCatalogXmlFileName, this);
				}
				astroCatalog.setSize(telescopeMonitorPanel.getPreferredSize().width, telescopeMonitorPanel.getPreferredSize().height);
				mainPane.addTab(astroCatologTabTitle, astroCatalog.getCatalogPanel());
			} 
			catch (StoneEdgeIIIException e) 
			{
				waitFrame.dispose();
				String errorMessage = "Could not open catalog\n" + e.getMessage();
				JOptionPane.showMessageDialog(this,
						errorMessage,
					    "Information",
					    JOptionPane.INFORMATION_MESSAGE);	
				astroCatalog = null;
			}
			waitFrame.dispose();
//			JOptionPane.showMessageDialog(this,"Tunnel connected to observatory","Information",JOptionPane.INFORMATION_MESSAGE);	
			return;
		}
	}
	private void disconnectStoneEdgeTunnel()
	{
		if (stoneEdgeIIITunnel == null)
		{
			return;
		}
		stoneEdgeIIITunnel.disconnect();
		stoneEdgeIIITunnel = null;
        findMenu(mainMenuBar, "Lock").setEnabled(false);
        findMenuItem(findMenu(mainMenuBar, "Connection"), "Disconnect").setEnabled(false);
        findMenuItem(findMenu(mainMenuBar, "Connection"), "Connect").setEnabled(true);

		cleanTabsOnDisconnect();
		
        findMenuItem(findMenu(mainMenuBar, "File"), "Change Catalog").setEnabled(false);
        findMenuItem(findMenu(mainMenuBar, "File"), "Reload Default Catalog").setEnabled(false);
		
//		JOptionPane.showMessageDialog(this,"Tunnel disconnected to observatory","Warning",JOptionPane.WARNING_MESSAGE);
	}
	
	private void cleanTabsOnDisconnect() {
		int domeCameraTabIndex = mainPane.indexOfTab(domeCameraTabTitle);
		if (domeCameraTabIndex > -1)
		{
			mainPane.setSelectedIndex(mainPane.indexOfTab(introPanelTabTitle));
			mainPane.remove(mainPane.indexOfTab(domeCameraTabTitle));
		}
		else
		{
			domeCameraFrame.dispose();
		}
		telescopeMonitorPanel.getDomeMonitorPanel().cleanup();

		deleteTab(astroCatalog, astroCatologTabTitle);
		deleteTab(targetingPanel, targetTabTitle);
		deleteTab(simbadPanel, simbadTabTitle);
	}
	
	private void deleteTab(Object panelObj, String panelName) {
		mainPane.remove(mainPane.indexOfTab(panelName));
		panelObj = null;
	}
	
	private void popOutDomeCamera()
	{
		mainPane.setSelectedIndex(mainPane.indexOfTab(introPanelTabTitle));
		mainPane.remove(mainPane.indexOfTab(domeCameraTabTitle));
		domeCameraFrame = new JFrame("Telescope monitor");
		domeCameraFrame.getContentPane().add(telescopeMonitorPanel);
		domeCameraFrame.setIconImage(logoIcon.getImage());
		domeCameraFrame.setVisible(true);
		telescopeMonitorPanel.getDomeMonitorPanel().setSize();
		domeCameraFrame.pack();
//		pack();
//		domeCameraFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		domeCameraFrame.addWindowListener(new java.awt.event.WindowAdapter() 
        {
            public void windowClosing(WindowEvent winEvt) 
            {
            	domeCameraFrame.dispose();
				mainPane.addTab(domeCameraTabTitle, telescopeMonitorPanel);
				mainPane.setSelectedIndex(mainPane.indexOfTab(domeCameraTabTitle));
				telescopeMonitorPanel.getDomeMonitorPanel().setSize();
//				pack();
           }
        });
	}
	private void reloadDefaultCatalog()
	{
		try 
		{
			astroCatalogXmlFileName = null;
	        InputStream inputStream = loader.getResourceAsStream(defaultAstroCatalogXmlFileName);
			astroCatalog = new AstroCatalog(inputStream, this);
			astroCatalog.setSize(telescopeMonitorPanel.getPreferredSize().width, telescopeMonitorPanel.getPreferredSize().height);
			mainPane.remove(mainPane.indexOfTab(astroCatologTabTitle));
			mainPane.addTab(astroCatologTabTitle, astroCatalog.getCatalogPanel());
			mainPane.setSelectedIndex(mainPane.indexOfTab(astroCatologTabTitle));
	        findMenuItem(findMenu(mainMenuBar, "File"), "Reload Default Catalog").setEnabled(false);
		} 
		catch (StoneEdgeIIIException e) 
		{
			String errorMessage = "Could not open catalog\n" + e.getMessage();
			JOptionPane.showMessageDialog(this,
					errorMessage,
				    "Information",
				    JOptionPane.INFORMATION_MESSAGE);	
			astroCatalog = null;
		}
	}
	private void changeCatalog()
	{
		String[] xmlExtensions = {"xml"};
		File catalogFile = chooseFile(lastDirectoryPath, "Open Catalog", "", false, xmlExtensions);
		if (catalogFile != null)
		{
			System.out.println(catalogFile.getPath());
			lastDirectoryPath = catalogFile.getParent();
			try 
			{
				astroCatalogXmlFileName = catalogFile.getPath();
				astroCatalog = new AstroCatalog(astroCatalogXmlFileName, this);
				astroCatalog.setSize(telescopeMonitorPanel.getPreferredSize().width, telescopeMonitorPanel.getPreferredSize().height);
				mainPane.remove(mainPane.indexOfTab(astroCatologTabTitle));
				mainPane.addTab(astroCatologTabTitle, astroCatalog.getCatalogPanel());
				mainPane.setSelectedIndex(mainPane.indexOfTab(astroCatologTabTitle));
		        findMenuItem(findMenu(mainMenuBar, "File"), "Reload Default Catalog").setEnabled(true);

			} 
			catch (StoneEdgeIIIException e) 
			{
				String errorMessage = "Could not open catalog\n" + e.getMessage();
				JOptionPane.showMessageDialog(this,
						errorMessage,
					    "Information",
					    JOptionPane.INFORMATION_MESSAGE);	
				astroCatalog = null;
			}
		}
	}
    public File chooseFile(String directoryPath, String dialogTitle, String selectedFileName, boolean saveDialog, String[] extensions) 
    {
    	File file = null;
    	JFileChooser fc = null;
    	if (directoryPath != null)
    	{
    		fc = new JFileChooser(directoryPath);
    	}
    	else
    	{
    		fc = new JFileChooser();
    	}
    	fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    	fc.setMultiSelectionEnabled(false);
    	fc.setSelectedFile(new File(selectedFileName));
        fc.addChoosableFileFilter(makeFileNameExtensionFilter(extensions));
        fc.setDialogTitle(dialogTitle);
        int returnVal = 0;
        if (saveDialog)
        {
            returnVal = fc.showSaveDialog(this);
        }
        else
        {
            returnVal = fc.showOpenDialog(this);
        }
        if (returnVal == JFileChooser.APPROVE_OPTION) 
        {
            file = fc.getSelectedFile();
        } 
        return file;
 	}
	FileNameExtensionFilter makeFileNameExtensionFilter(String[] extensions)
	{
		int numExtensions = 0;
		for (int ii = 0; ii < extensions.length; ++ii) if (extensions[ii] != null) numExtensions = numExtensions + 1;
		String[] nne = new String[numExtensions];
		int iext = 0;
	   	String extensionDesc = "";
		for (int ii = 0; ii < extensions.length; ++ii) 
		{
			if (extensions[ii] != null)
			{
				nne[iext] = extensions[ii];
				if (iext == 0 ) extensionDesc = extensionDesc + "*." + extensions[ii];
				if (iext >  0 ) extensionDesc = extensionDesc + ", *." + extensions[ii];
				iext = iext + 1;
			}
		}
		if (numExtensions == 1) return new FileNameExtensionFilter(extensionDesc, nne[0]);
		if (numExtensions == 2) return new FileNameExtensionFilter(extensionDesc, nne[0], nne[1]);
		if (numExtensions == 3) return new FileNameExtensionFilter(extensionDesc, nne[0], nne[1], nne[2]);
		if (numExtensions >= 4) return new FileNameExtensionFilter(extensionDesc, nne[0], nne[1], nne[2], nne[3]);
		return null;
	}
	public TelescopeMonitorPanel getTelescopeMonitorPanel() {return telescopeMonitorPanel;}
	public StoneEdgeIIITunnel getStoneEdgeIIITunnel() {return stoneEdgeIIITunnel;}
	public TargetingPanel getTargetingPanel() {return targetingPanel;}
	public StatusPanel getStatusBar() {return statusBar;}
	public JTabbedPane getMainPane() {return mainPane;}
	public String getTargetTabTitle() {return targetTabTitle;}
	public TelescopeInfo getTelescopeInfo() {return telescopeInfo;}
	public int getStatusTableLength() {return statusTableLength;}
	public String getUserKey() {return userKey;}
	public int getDomeSleepTimerSeconds() {return domeSleepTimerSeconds;}
	public int getDomeTrackingIntervalHeartBeatCount() {return domeTrackingIntervalHeartBeatCount;}
	public AstroCatalog getAstroCatalog() {return astroCatalog;}
	public Date getUpdateDate() {return updateDate;}
	
	public void setTelescopeInfo(TelescopeInfo telescopeInfo) {this.telescopeInfo = telescopeInfo;}
	public static void main(String[] args) throws StoneEdgeIIIException  
	{
		int domeSleepTimerSeconds = 30;
		int domeTrackingIntervalHeartBeatCount = 4;
    	int statusTableLength = 100;
	    new StoneEdgeIIIGui(domeSleepTimerSeconds, domeTrackingIntervalHeartBeatCount, statusTableLength, "StoneEdgeIII");
	}

}
